package com.zzvcom.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public abstract class IMGTools
{

    /**
     * 函数介绍： 参数： 返回值：
     */

    public static void main(String[] args)
    {
        String html = imgSrc(" <IMG height='1000'  src=\"http://222.137.107.196:8080/userfiles/image/contact%20us/skypeicon.gif\" width='45' ssA > <IMG height='1000'  src='abc.jgp' width='45' ssA />");

        System.out.println(html);
    }

    public static final String regex = "<img[^>]+(src=(('[^>'\"]*')|(\"[^>'\"]*\")))[^>]*>";

    public static String imgSrc(String html)
    {
        Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
        Matcher m = p.matcher(html);
        List<String> list = new ArrayList<String>();
        while (m.find())
        {
            list.add(m.group(1));
        }

        for (String fstr : list)
        {
            String pies[] = null;
            String q = null;
            if (fstr.indexOf("'") > 0)
            {
                pies = fstr.split("'");
                q = "'";
            }
            else if (fstr.indexOf("\"") > 0)
            {
                pies = fstr.split("\"");
                q = "\"";
            }
            if (pies != null)
            {
                if (pies[1].indexOf(":8080/") > 0)
                {
                    String splits[] = pies[1].split(":8080/");
                    html = html
                            .replace(fstr, pies[0] + q + "/" + splits[1] + q);
                }
            }
        }
        return html;
    }

    public static final String MSN = "http://msnim:chat/?contact=yilongcarpet@hotmail.com";

    public static final String _MSN = "msnim:chat?contact=yilongcarpet@hotmail.com";

    public static final String SKYPE = "http://skype:yilongcarpet/?call";

    public static final String _SKYPE = "skype:yilongcarpet?call";

    public static String skypeAndMsn(String html)
    {

        return html.replace(MSN, _MSN).replace(SKYPE, _SKYPE);

    }
}
